package com.bml.www.teacher.account.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.bml.www.teacher.R;
import com.bml.www.teacher.account.forgetpwd.ForgetPwdActivity;
import com.bml.www.teacher.account.utils.FragmentUtils;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.frameworkbase.customviews.IconTextArrowEditText;
import com.pachong.android.frameworkbase.customviews.edittext.PasswordEditText;
import com.pachong.android.frameworkbase.utils.MD5Util;
import com.pachong.android.frameworkbase.utils.RegularUtils;

import butterknife.Bind;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity {

    @Bind(R.id.itetPhone)
    IconTextArrowEditText mItetPhone;
    @Bind(R.id.itetPassword)
    PasswordEditText mItetPassword;
    @Bind(R.id.btnLogin)
    Button mBtnLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initToolBar();

    }
    public static void start(Activity activity){
        Intent intent = new Intent(activity, LoginActivity.class);
        activity.startActivity(intent);
    }

    private void initToolBar() {
        hideToolbar();
//        enableBackButton();
//        getCustomToolbar().setTitle(R.string.login);
//        getCustomToolbar().addRightButton(R.string.register, new RegistBtnListener());
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_login, null);
    }

    private String getPhone() {
        return mItetPhone.getEditText().trim();
    }

    private String getPassWord() {
        return mItetPassword.getPassword().toString();
    }

    @OnClick({R.id.btnLogin, R.id.tvResit, R.id.tvForget})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btnLogin:
                break;
            case R.id.tvResit:
                RegistActivity.start(LoginActivity.this);
                break;
            case R.id.tvForget:
            ForgetPwdActivity.start(LoginActivity.this);
                break;
        }
    }

    private void login() {
        if (TextUtils.isEmpty(getPhone())) {
            FragmentUtils.showWarnDialog("手机号不能为空", getSupportFragmentManager());
            return;
        } else if (TextUtils.isEmpty(getPassWord())) {
            FragmentUtils.showWarnDialog("密码不能为空", getSupportFragmentManager());
            return;
        } else if (!RegularUtils.isMobileSimple(getPhone())) {
            FragmentUtils.showWarnDialog("输入的手机号有误", getSupportFragmentManager());
            return;
        } else if (!RegularUtils.isPassword(getPassWord())) {
            FragmentUtils.showWarnDialog("密码最多为6-20个字符", getSupportFragmentManager());
            return;
        }
        String enCodePwd = MD5Util.getMd5(getPassWord());//Md5加密
//        setLoginRequest(getPhone(), enCodePwd);
    }




    private class RegistBtnListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            RegistActivity.start(LoginActivity.this);
        }
    }


}
